package com.bbex.entity;

import com.bbex.sql.SqlField;
import com.bbex.sql.SqlTable;
import com.bbex.vo.UserCoinVolumeVO;
import com.bbex.vo.redis.RedisUserCoinVolume;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 用户资产
 *
 * @author xiaoyu
 */
@SqlTable("js_plat_user_coin_volume")
@Data
public class UserCoinVolume extends BaseEntity {

    @SqlField("user_id")
    private String userId;

    @SqlField("volume")
    private BigDecimal volume;

    @SqlField("lock_volume")
    private BigDecimal lockVolume;

    @SqlField("out_lock_volume")
    private BigDecimal outLockVolume = BigDecimal.ZERO;

    @SqlField("coin_id")
    private String coinId;

    @SqlField("coin_symbol")
    private String coinSymbol;

    @SqlField("flag")
    private Short flag;

    @SqlField("flag_mark")
    private String flagMark;

    @SqlField("version")
    private Long version = 0L;

    @SqlField("create_by")
    private String create_by;

    @SqlField("update_by")
    private String update_by;

    public String getCreate_by() {
        return create_by;
    }

    public void setCreate_by(String create_by) {
        this.create_by = create_by;
    }

    public String getUpdate_by() {
        return update_by;
    }

    public void setUpdate_by(String update_by) {
        this.update_by = update_by;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public BigDecimal getVolume() {
        return volume;
    }

    public void setVolume(BigDecimal volume) {
        this.volume = volume;
    }

    public BigDecimal getLockVolume() {
        return lockVolume;
    }

    public void setLockVolume(BigDecimal lockVolume) {
        this.lockVolume = lockVolume;
    }

    public BigDecimal getOutLockVolume() {
        return outLockVolume;
    }

    public void setOutLockVolume(BigDecimal outLockVolume) {
        this.outLockVolume = outLockVolume;
    }

    public String getCoinId() {
        return coinId;
    }

    public void setCoinId(String coinId) {
        this.coinId = coinId;
    }

    public String getCoinSymbol() {
        return coinSymbol;
    }

    public void setCoinSymbol(String coinSymbol) {
        this.coinSymbol = coinSymbol;
    }

    public Short getFlag() {
        return flag;
    }

    public void setFlag(Short flag) {
        this.flag = flag;
    }

    public String getFlagMark() {
        return flagMark;
    }

    public void setFlagMark(String flagMark) {
        this.flagMark = flagMark;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * 转换成VO.
     *
     * @param redisUserCoinVolume redis对象
     * @return UserCoinVolumeVO
     */
    public static UserCoinVolumeVO transform(final RedisUserCoinVolume redisUserCoinVolume) {
        if (Objects.isNull(redisUserCoinVolume)) {
            return new UserCoinVolumeVO();
        }
        UserCoinVolumeVO volumeVO = new UserCoinVolumeVO();
        volumeVO.setCoinSymbol(redisUserCoinVolume.getCoinSymbol());
        volumeVO.setUserId(redisUserCoinVolume.getUserId());
        volumeVO.setVolume(redisUserCoinVolume.getVolume());
        volumeVO.setLockVolume(redisUserCoinVolume.getLockVolume());
        return volumeVO;
    }


    /**
     * 转换成VO.
     *
     * @param redisUserCoinVolume 数据库实体
     * @return UserCoinVolume
     */
    public static UserCoinVolume transformToRedis(final RedisUserCoinVolume redisUserCoinVolume) {
        if (Objects.isNull(redisUserCoinVolume)) {
            return new UserCoinVolume();
        }
        UserCoinVolume userCoinVolume = new UserCoinVolume();
        userCoinVolume.setId(redisUserCoinVolume.getId());
        userCoinVolume.setCoinId(redisUserCoinVolume.getCoinId());
        userCoinVolume.setCoinSymbol(redisUserCoinVolume.getCoinSymbol());
        userCoinVolume.setUserId(redisUserCoinVolume.getUserId());
        userCoinVolume.setVolume(redisUserCoinVolume.getVolume());
        userCoinVolume.setLockVolume(redisUserCoinVolume.getLockVolume());
        userCoinVolume.setCreateDate(LocalDateTime.now());
        userCoinVolume.setUpdateDate(LocalDateTime.now());
        userCoinVolume.setFlag(redisUserCoinVolume.getFlag());
        userCoinVolume.setFlagMark(redisUserCoinVolume.getFlagMark());
        userCoinVolume.setCreate_by("bbex");
        userCoinVolume.setUpdate_by("bbex");
        return userCoinVolume;
    }


}
